<!--  -->
<template>
  <div>
    <van-popup v-model="changeCompany" round :close-on-click-overlay="false">
      <div class="popup-control-box flex">
        <div class="popup-control-box-title s-15">切换企业</div>
        <div class="popup-control-main">
          <van-radio-group v-model="radio" checked-color="#ee0a24">
            <van-cell-group>
              <van-cell :title="item.name" clickable @click="onClickRadie(item.id)" v-for="item in list" :key="item.id">
                <template #right-icon>
                  <van-radio :name="item.id" />
                </template>
              </van-cell>
            </van-cell-group>
          </van-radio-group>
        </div>
        <div class="s-11" style="color: #18b494; text-align: left; padding: 0 10px;" @click="addCompany">新增企业</div>
        <div class="popup-control-btn flex-j-sa">
          <van-button type="default" size="small" @click="hiddenPop">取消</van-button>
          <van-button type="danger" size="small" @click="changeCid">切换</van-button>
        </div>
      </div>
    </van-popup>
  </div>
</template>

<script>
export default {
  props: {
    value: {
      type: Boolean,
      default: false
    },
    list: {
      type: Array,
      default: ()=> []
    },
  },
  watch: {
    value(val) {
      this.changeCompany = val;
      if (val) {}
    }
  },
  data() {
    return {
      changeCompany: false,
      radio: "1"
    };
  },
  components: {},
  computed: {},
  methods: {
    onClickRadie(id){
      this.radio = id;
    },
    changeCid() {
      this.$emit("changeCid", {cid: this.radio});
      this.hiddenPop();
    },
    addCompany(){
      this.$emit("addCompany");
    },
    hiddenPop(){
      this.$emit("input", false);
    }
  }
};
</script>
<style lang="scss" rel="stylesheet/scss" scoped>
.van-cell__title {
  text-align: left;
}

.popup-control-box {
  width: 18.875rem;
  flex-direction: column;

  .popup-control-box-title {
    height: 3rem;
    line-height: 3rem;
  }

  .popup-control-main {
    max-height: 19rem;
    overflow: scroll;
  }

  .popup-control-main::-webkit-scrollbar {
    width: 0 !important;
  }

  .popup-control-btn {
    margin: 10px;
  }

  .van-button--small {
    width: 80px;
  }
}
</style>
